package com.testfileupload.uploadimg.design.state;

public class Lift implements ILift{
    private int state;
    @Override
    public void setState(int state) {
        this.state = state;
    }

    @Override
    public void open() {
//        System.out.println("电梯门开启");
        switch (this.state){
            case OPENING_STATE:
                break;
            case CLOSEING_STATE:
                this.openWithoutLogic();
                this.setState(OPENING_STATE);
                break;
            case RUNNING_STATE:
                break;
            case STOPPING_STATE:
                this.openWithoutLogic();
                this.setState(OPENING_STATE);
                break;
        }
    }

    private void openWithoutLogic() {
        System.out.println("开门逻辑");
    }

    @Override
    public void close() {
//        System.out.println("电梯门关闭");
        //电梯什么时候可以关闭
        switch (this.state){
            case OPENING_STATE://开门的状态可以关
                this.closeWithoutLogic();
                this.setState(CLOSEING_STATE);
                break;
            case CLOSEING_STATE://关门的状态什么也不做
                break;
            case RUNNING_STATE://运行中，门是关的什么也不做
                break;
            case STOPPING_STATE://停止状态，门是关的什么也不做
                break;
        }
    }

    private void closeWithoutLogic() {
        System.out.println("电梯门关闭");
    }

    @Override
    public void run() {
//        System.out.println("电梯上下运行起来");
        switch (this.state){
            case OPENING_STATE://开门的状态什么都不做
                break;
            case CLOSEING_STATE://关门的状态可以运行
                this.runWithoutLogic();
                this.setState(RUNNING_STATE);
                break;
            case RUNNING_STATE://运行中，什么也不做
                break;
            case STOPPING_STATE://停止状态，可以运行
                this.runWithoutLogic();
                this.setState(RUNNING_STATE);
                break;
        }
    }

    private void runWithoutLogic() {
        System.out.println("运行状态");
    }

    @Override
    public void stop() {
//        System.out.println("电梯停止");
        switch (this.state){
            case OPENING_STATE://开门的状态什么都不做
                break;
            case CLOSEING_STATE://关门的状态可以停止
                this.stopWithoutLogic();
                this.setState(STOPPING_STATE);
                break;
            case RUNNING_STATE://运行中，可停止
                this.stopWithoutLogic();
                this.setState(STOPPING_STATE);
                break;
            case STOPPING_STATE://停止状态，什么也不做
                break;
        }
    }

    private void stopWithoutLogic() {
        System.out.println("停止");
    }
}
